package com.hog.web.controller;

import com.hog.entity.BlogArticleWeb;
import com.hog.service.article.IBlogArticleWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 文章详情控制层
 *
 * @author 唐晴
 * @date 2020年08月11日
 * @since JDK 1.8
 */
@Controller
@RequestMapping("/detail")
public class DetailController {
    @Autowired
    private IBlogArticleWebService articleWebService;

    @GetMapping("/{type}/{id}.html")
    public String getArticleInfo(@PathVariable("type") String type, @PathVariable("id") String id, Model model) {
        BlogArticleWeb blogArticleWeb = articleWebService.getBlogArticleWeb(id);
        model.addAttribute("article", blogArticleWeb);
        model.addAttribute("randomList", articleWebService.randomRecommendation());
        model.addAttribute("sharingList", articleWebService.getSharingList());
        return "blog_detail";
    }
}